package com.ly.web.controller.erp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ly.common.constant.HttpStatus;
import com.ly.heart.domain.CustomerEntity;
import com.ly.heart.domain.dto.CustomerDto;
import com.ly.heart.domain.dto.WarehouseDto;
import com.ly.heart.domain.vo.WarehouseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.WarehouseEntity;
import com.ly.heart.service.IWarehouseService;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

/**
 * 仓库Controller
 * @author cxl
 * @date 2024-05-14
 */
@Api (value = "Warehouse", tags = "仓库")
@RestController
@RequestMapping ("/heart/Warehouse")
public class WarehouseController extends BaseController {
    @Autowired
    private IWarehouseService warehouseEntityService;

    /**
     * 查询仓库列表
     */
    //@PreAuthorize ("@ss.hasPermi('heart:Warehouse:list')")
    @GetMapping ("/list")
    @ApiOperation ("查询仓库列表")
    public TableDataInfo list (WarehouseDto warehouseDto) {
        IPage<WarehouseVo> warehouseVoIPage = warehouseEntityService.selectNewWarehouseListCopy(warehouseDto);
        TableDataInfo tableDataInfo = new TableDataInfo ();
        tableDataInfo.setRows ( warehouseVoIPage.getRecords() );
        tableDataInfo.setTotal ( warehouseVoIPage.getTotal() );
        tableDataInfo.setCode ( HttpStatus.SUCCESS );
        return tableDataInfo;
    }


    @PreAuthorize ("@ss.hasPermi('heart:Warehouse:detailList')")
    @GetMapping ("/detailList")
    @ApiOperation ("仓库关键词全量查询")
    public AjaxResult detailList (WarehouseDto warehouseDto) {
        IPage<WarehouseVo> warehouseVoIPage = warehouseEntityService.selectWarehouseEntityListCopy ( warehouseDto );
        return AjaxResult.success ( warehouseVoIPage );
    }

    /**
     * 导出仓库列表
     */
//    @PreAuthorize ("@ss.hasPermi('heart:Warehouse:export')")
//    @Log (title = "仓库", businessType = BusinessType.EXPORT)
//    @PostMapping ("/export")
//    @ApiOperation ("导出仓库列表")
//    public void export (HttpServletResponse response, WarehouseEntity warehouseEntity) {
//        List<WarehouseEntity> list = warehouseEntityService.selectWarehouseEntityList ( warehouseEntity );
//        ExcelUtil<WarehouseEntity> util = new ExcelUtil<WarehouseEntity> ( WarehouseEntity.class );
//        util.exportExcel ( list, "仓库数据" );
//    }

    /**
     * 获取仓库详细信息
     */
    @PreAuthorize ("@ss.hasPermi('heart:Warehouse:query')")
    @GetMapping (value = "/{id}")
    @ApiOperation ("获取仓库详细信息")
    public AjaxResult getInfo (@PathVariable ("id") String id) {
        return AjaxResult.success ( warehouseEntityService.selectWarehouseEntityById ( id ) );
    }


    /**
     * 新增仓库
     */
    @PreAuthorize ("@ss.hasPermi('heart:Warehouse:add')")
    @Log (title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation ("新增仓库")
    public AjaxResult add (@RequestBody WarehouseEntity warehouseEntity) {
        return  warehouseEntityService.insertWarehouseEntity ( warehouseEntity );
    }

    /**
     * 修改仓库
     */
    @PreAuthorize ("@ss.hasPermi('heart:Warehouse:edit')")
    @Log (title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation ("修改仓库")
    public AjaxResult edit (@RequestBody WarehouseEntity warehouseEntity) {
        return warehouseEntityService.updateWarehouseEntity ( warehouseEntity ) ;
    }

    /**
     * 删除仓库
     */
    @PreAuthorize ("@ss.hasPermi('heart:Warehouse:remove')")
    @Log (title = "仓库", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{ids}")
    @ApiOperation ("删除仓库")
    public AjaxResult remove (@PathVariable String[] ids) {
        return warehouseEntityService.deleteWarehouseEntityByIds ( ids ) ;
    }


    /**
     * 禁用仓库
     */
    @Log (title = "禁用仓库", businessType = BusinessType.DELETE)
    @RequestMapping ("disabled")
    @ApiOperation ("禁用仓库")
    public AjaxResult disabled (String id) {
        return warehouseEntityService.disable ( id );
    }
}
